package com.usian.controller;

import com.usian.common.model.course.CourseComment;
import com.usian.common.model.member.MemberCatalog;
import com.usian.common.untils.Result;
import com.usian.service.CatalogFeignService;
import com.usian.service.CourseFeignService;
import com.usian.service.MemberCatalogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @projectName: 2210A-project1
 * @package: com.usian.controller
 * @className: CourseController
 * @author: 莫洪维
 * @email: 1204315800@qq.com
 * @description: TODO
 * @date: 2023/8/25 17:28
 */
@RestController
@RequestMapping("/course")
public class CourseController {

    @Autowired
    private CatalogFeignService catalogFeignService;
    @Autowired
    private MemberCatalogService memberCatalogService;
    @Autowired
    private CourseFeignService courseFeignService;

    /**
     * 添加评论方法
     * @param courseComment
     * @return
     */
    @RequestMapping(value = "/saveComment",method = RequestMethod.POST)
    public Result saveComment(@RequestBody CourseComment courseComment){
        //调用方法添加评论
        return courseFeignService.saveComment(courseComment);
    }

    /**
     * 查询所有评论信息方法
     * @return
     */
    @RequestMapping(value = "/findAllComment",method = RequestMethod.GET)
    public Result findAll(CourseComment courseComment){
        //调用方法查询评论信息
        return courseFeignService.findAllComment(courseComment);
    }

    /**
     * 为登录成员添加学习进度方法
     * */
    @RequestMapping(value = "/saveMemberCatalog",method = RequestMethod.POST)
    public Result saveMemberCatalog(@RequestBody MemberCatalog memberCatalog){
        //调用方法进行查询
        Integer i = memberCatalogService.saveMemberCatalog(memberCatalog);
        //判断是否成功
        return i != 0 ? Result.ok().message("已添加学习进度") : Result.error().message("添加失败");
    }

    /**
     * 根据成员id和目录id删除学习进度方法
     */
    @RequestMapping(value = "/delCatalogId",method = RequestMethod.DELETE)
    public Result delCatalogId(MemberCatalog memberCatalog){
        //调用方法进行删除
        Integer i = memberCatalogService.delCatalogId(memberCatalog.getMemberId(), memberCatalog.getCatalogId(),memberCatalog.getCourseId());
        //判断是否成功
        return i != 0 ? Result.ok().message("已删除学习进度") : Result.error().message("删除失败");
    }

    /**
     * 根据成员id查询学习进度方法
    * */
    @RequestMapping(value = "/findCatalogByMemberId",method = RequestMethod.GET)
    public Result findCatalogByMemberId(Long id,Long courseId){
        //调用方法进行查询
        List<Long> catalogIds = memberCatalogService.findByMemberId(id,courseId);
        return Result.ok().message("查询成功").data("catalogIds",catalogIds);
    }

    /**
     * 根据课程id查询目录方法
     * */
    @RequestMapping(value = "/findAllCatalog",method = RequestMethod.GET)
    public Result findAll(Long id){
        //调用方法进行查询
        Result result = catalogFeignService.findAll(id);
        return result;
    }

}
